PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/WpfCSharp/AutodeskReCapClient/AdskDynamicDictionary.cs

https://github.com/PandazZ/Autodesk-ReCap-Samples
C# | 64 lines | 30 code | 10 blank | 24 comment | 0 complexity | cf240a55099c50ea44476de988719c29 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. // (C) Copyright 2014 by Autodesk, Inc.
  2. //
  3. // Permission to use, copy, modify, and distribute this software in
  4. // object code form for any purpose and without fee is hereby granted,
  5. // provided that the above copyright notice appears in all copies and
  6. // that both that copyright notice and the limited warranty and
  7. // restricted rights notice below appear in all supporting
  8. // documentation.
  9. //
  10. // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  11. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  12. // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
  13. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  14. // UNINTERRUPTED OR ERROR FREE.
  15. //- Written by Cyrille Fauvel, Autodesk Developer Network (ADN)
  16. //- http://www.autodesk.com/joinadn
  17. //- April 20th, 2014
  18. //
  19. using System;
  20. using System.Collections.Generic;
  21. using System.ComponentModel;
  22. using System.Linq;
  23. using System.Text;
  24. using System.Threading.Tasks;
  25. using System.Xml;
  26. using System.Xml.Linq;
  27. using System.Dynamic;
  28. using Newtonsoft.Json;
  29. using Newtonsoft.Json.Linq;
  30. namespace Autodesk.ADN.Toolkit.ReCap {
  31. public class AdskDynamicDictionary : DynamicObject {
  32. public Dictionary<string, object> Dictionary { get; internal set; }
  33. public AdskDynamicDictionary () : base () {
  34. Dictionary =new Dictionary<string, object> () ;
  35. }
  36. public int Count {
  37. get { return (Dictionary.Count) ; }
  38. }
  39. public override bool TryGetMember (GetMemberBinder binder, out object result) {
  40. // Converting the property name to lowercase so that property names become case-insensitive.
  41. string name =binder.Name/*.ToLower ()*/ ;
  42. // If the property name is found in a dictionary, set the result parameter to the property value and return true.
  43. // Otherwise, return false.
  44. return (Dictionary.TryGetValue (name, out result)) ;
  45. }
  46. // If you try to set a value of a property that is not defined in the class, this method is called.
  47. public override bool TrySetMember (SetMemberBinder binder, object value) {
  48. // Converting the property name to lowercase so that property names become case-insensitive.
  49. Dictionary [binder.Name/*.ToLower ()*/] =value ;
  50. // You can always add a value to a dictionary, so this method always returns true.
  51. return (true) ;
  52. }
  53. }
  54. }